#include <time.h>

const unsigned long maxshort = 65536L;
const unsigned long multiplier = 1194211693L;
const unsigned long adder = 12345L;


class RandomNumber
{
private :
	unsigned long randSeed;
public :
	RandomNumber(unsigned long s = 0)
	{
		if( s == 0 )
			randSeed = time(0);
		else
			randSeed = s;
	}
	unsigned short random(unsigned long n)//产生0:n-1之间的随机数
	{
		randSeed = multiplier * randSeed + adder;
		return (unsigned short)( (randSeed >> 16) % n );
	}
	double fRandom(void)//产生[0,1)之间的随机数
	{
		return random( maxshort) / double(maxshort);
	}
};

